<?php

namespace backend\controllers;
use Yii;
use yii\web\UploadedFile;
class NodeController extends \yii\web\Controller
{
	//引入左侧 和 头部
	public $layout='main1.php';
	//添加权限
	public function actionAdd()
	{
	    $model = new \backend\models\NodeModel();	
	    if ($_POST) 
	    {
	        $model->node_name=$_POST['node_name'];
	        $model->node_controller=$_POST['node_controller'];
	        $model->node_method=$_POST['node_method'];
	        $model->node_pid=$_POST['node_pid'];
	        $model->node_status=isset($_POST['text'])?1:0;
	        if($model->save())
	        {
	        	$u=Yii::$app->db->createCommand("update seven_node set node_pid = '$node_pid' WHERE node_id = '$id'")->execute();        	      	
	        }
	        else
	        {
	        	return $this->goHome();
	        }
	    }
	    $q=Yii::$app->db->createCommand("select * from seven_node where node_status = 1")->queryAll();
	    $q = $model -> getNodeOrder($q);
	    return $this->render('add', [
	        'model' => $model,
	        'data'=>$q,
	    ]);
	}
	//展示权限
		public function actionShow()
		{

		    $model = new \backend\models\NodeModel();
	        if (Yii::$app->request->isPost) {
	            $model->file = UploadedFile::getInstance($model, 'file');

	            if ($model->file && $model->validate()) {                
	                $model->file->saveAs('uploads/' . $model->file->baseName . '.' . $model->file->extension);
	            print_r($_FILES);
	            exit;
	            }
	        }
		    if ($model->load(Yii::$app->request->post())) {
		        if ($model->validate()) {
		           
		        }
		    }
		    return $this->render('show', [
		        'model' => $model,
		    ]);
		}
}
